<template>
    <list-layout>
        <div slot="search">
            <el-form :model="queryParams" :inline="true" ref="queryForm" v-show="showSearch" label-width="88px">
                <!--                 <el-form-item label="来料分类" prop="materialClassify">
                    <el-select v-model="queryParams.materialClassify" :placeholder="$t('public.select_holder',{select_holder: '来料分类'})" style="width:100%;" filterable clearable size="small">
                        <el-option label="采购入库" value="采购入库" />
                        <el-option label="调拨入库" value="调拨入库" />
                        <el-option label="部门/研发调用归还" value="部门/研发调用归还" />
                    </el-select>
                </el-form-item>-->
                <el-form-item :label="$t('inventoryManagement.factory')" prop="factoryCode">
                    <!-- <el-select v-model="queryParams.factoryCode" :placeholder="$t('public.select_holder',{select_holder: $t('inspectionManagement.plantArea')})" style="width:100%;" filterable clearable size="small">
                        <el-option v-for="(item) in factoryList" :key="item.plantCode" :label="item.plantName" :value="item.plantName" />
                    </el-select> -->
                    <FactoryDialog v-model="queryParams.factoryName" @callback="({plantCode})=>queryParams.factoryCode = plantCode" />
                </el-form-item>
                <!--                <el-form-item :label="$t('inventoryManagement.supplierBatchNo')" prop="lichn">
                    <el-input v-model="queryParams.lichn" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('inventoryManagement.supplierBatchNo'),
                      })
                    " clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>-->
                <!--                <el-form-item :label="$t('inventoryManagement.batch')" prop="lot">
                    <el-input v-model="queryParams.lot" :placeholder="
                      $t('public.placeholder', {
                        placeholder: $t('inventoryManagement.batch'),
                      })
                    " clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>-->
                <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                    <el-input v-model="queryParams.materialName" :placeholder="
              $t('public.placeholder', {
                placeholder: $t('inventoryManagement.materialName'),
              })
            " clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                    <el-input v-model="queryParams.materialCode" :placeholder="
              $t('public.placeholder', {
                placeholder: $t('inventoryManagement.materialNo'),
              })
            " clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                    <el-input v-model="queryParams.supplierCode" :placeholder="
              $t('public.placeholder', {
                placeholder: $t('inventoryManagement.supplierNo'),
              })
            " clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inspectionManagement.InspectBatchNo')" prop="inspectionLotMark">
                    <el-input v-model="queryParams.inspectionLotMark" :placeholder="
              $t('public.placeholder', {
                placeholder: $t('inspectionManagement.InspectBatchNo'),
              })
            " clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>
                <el-form-item :label="$t('inventoryManagement.isInspected')" prop="isIncomingInspection">
                    <el-select v-model="queryParams.isIncomingInspection" :placeholder="$t('public.select_holder',{select_holder: $t('inventoryManagement.isInspected')})" style="width:100%;" filterable clearable size="small">
                        <el-option key="0" :label="$t('public.no')" value="0" />
                        <el-option key="1" :label="$t('public.yes')" value="1" />
                    </el-select>
                </el-form-item>
              <el-form-item :label="$t('inventoryManagement.preInspectionOrNot')" prop="checkArt">
                <el-select v-model="queryParams.checkArt" :placeholder="
              $t('public.select_holder', {
                select_holder: $t('inventoryManagement.preInspectionOrNot'),
              })
            " style="width: 100%" clearable size="small">
                  <el-option key="1" :label="$t('public.yes')" value="1"> </el-option>
                  <el-option key="0" :label="$t('public.no')" value="0"> </el-option>
                </el-select>
              </el-form-item>
                <!-- <el-form-item :label="$t('inventoryManagement.inspectionOrderstatus')" prop="sheetStatus">
                    <el-select v-model="queryParams.sheetStatus" :placeholder="
              $t('public.select_holder', {
                select_holder: $t('inventoryManagement.inspectionOrderstatus'),
              })
            " clearable style="width: 100%" size="small">
                        <el-option key="0" label="全部" value="0" />
                        <el-option key="1" label="已完成" value="1" />
                        <el-option key="2" label="未发起" value="2" />
                        <el-option key="3" label="正在进行中" value="3" />
                        <el-option key="4" label="异常处理中" value="4" />
                    </el-select>
                </el-form-item> -->
                <!-- <el-form-item :label="$t('inventoryManagement.approvalStatus')" prop="approveStatus">
                    <el-select v-model="queryParams.approveStatus" :placeholder="
              $t('public.select_holder', {
                select_holder: $t('inventoryManagement.approvalStatus'),
              })
            " clearable style="width: 100%" size="small">
                        <el-option key="0" label="全部" value="" />
                        <el-option key="1" label="通过" value="0" />
                        <el-option key="2" label="不通过" value="1" />
                        <el-option key="3" label="未审批" value="2" />
                    </el-select>
                </el-form-item> -->

                   <!-- <el-form-item :label="$t('inventoryManagement.arrivalTime')" prop="cpudt">
                    <el-date-picker style="width: 214px" v-model="queryParams.cpudt" size="small" value-format="yyyy-MM-dd" type="daterange" start-placeholder="开始日期" end-placeholder="结束日期">
                    </el-date-picker>
                </el-form-item> -->

                <!-- prop="dateRange" -->
                <!-- v-model="dateRange" -->

                <el-form-item :label="$t('inventoryManagement.arrivalTime')" prop="params">
                    <el-date-picker style="width: 214px" v-model="queryParams.params" size="small" value-format="yyyy-MM-dd" type="daterange" :start-placeholder="$t('tips.beginInput')" :end-placeholder="$t('tips.endInput')">
                    </el-date-picker>
                </el-form-item>
                <!--filter: inspection order-->
                <el-form-item :label="$t('inventoryManagement.splitItemsTbColInspectionCode')" prop="inspectionOrder">
                    <el-input v-model="queryParams.inspectionOrder" :placeholder="
              $t('public.placeholder', {placeholder: $t('inventoryManagement.splitItemsTbColInspectionCode'),})" clearable size="small" @keyup.enter.native="handleQuery" />
                </el-form-item>


            </el-form>

            <div style="display: flex; justify-content: center">
                <el-button type="primary" icon="el-icon-search" size="mini" @click="searchQuery">{{ $t("public.search") }}</el-button>
                <el-button icon="el-icon-refresh" class="resectBtn" size="mini" @click="resetQuery">{{
            $t("public.reset")
            }}</el-button>
            </div>
        </div>

        
        <div class="app-container ">
            <div class="container-header">
                <div class="header-left">
                    {{ $t("inventoryManagement.InspectedInventory") }}
                </div>
                <el-button-group class="header-right">
                    <el-button type="primary" size="small" :class="selBtn === 1 ? 'selBtn' : 'unselBtn'" @click="changeBtn(1)">{{ $t("inventoryManagement.group") }}</el-button>
                    <el-button type="primary" size="small" :class="selBtn === 2 ? 'selBtn' : 'unselBtn'" style="border-left: 1px solid #0b7be3" @click="changeBtn(2)">{{ $t("inventoryManagement.detail") }}</el-button>
                </el-button-group>
            </div>
            <el-row :gutter="10" class="mb8 btnGroup" v-show="selBtn === 2">
                <el-col :span="1.5">
                    <el-button type="primary" :loading="loading" icon="el-icon-plus" size="mini" @click="handleDetailAdd(0)" v-hasPermi="['ny-iqc:inventory:getCheckoutEcho']">{{ $t("inventoryManagement.addInspection") }}</el-button>
                </el-col>
                <el-col :span="1.5">
                            <!-- v-hasPermi="['ny-iqc:inventory:addSplitInspection']" -->
                    <el-button type="primary" :loading="loadingSplitInfo"  size="mini" @click="openSplitInspect" v-hasPermi="['ny-iqc:inventory:splitInspection']">{{ $t("inventoryManagement.addSplitInspection") }}</el-button>
                    <!-- <el-button type="primary"   size="mini" @click="openSplitInspect" v-hasPermi="['ny-iqc:inventory:getCheckoutEcho']">{{ $t("inventoryManagement.addSplitInspection") }}</el-button> -->
                </el-col>

                <el-col :span="1.5">
                            <!-- v-hasPermi="['ny-iqc:inventory:addSplitInspection']" -->
                            <el-button  type="primary"  size="mini" @click="openCombine" v-hasPermi="['ny-iqc:inventory:recoverSplit']">{{ $t("inventoryManagement.combineSplit") }}</el-button>
                            <!-- <el-button  type="primary"  size="mini" @click="openCombine" v-hasPermi="['ny-iqc:inventory:getCheckoutEcho']">{{ $t("inventoryManagement.combineSplit") }}</el-button> -->
                </el-col>
                <el-col :span="1.5">
                    <el-button type="primary" :loading="loading" icon="el-icon-plus" size="mini" @click="handleDetailAdd(1)" v-hasPermi="['ny-iqc:inventory:getCheckoutEcho']">{{ $t("inventoryManagement.initiateExperimentalTasks") }}</el-button>
                </el-col>
                
                <!-- <el-col :span="1.5">
                    <el-button size="mini" class="importitemBtn" @click="handleApproval" v-hasPermi="['ny-iqc:inventory:approve']"><img src="@/assets/images/icons/batch-approve.png" alt="" />
                        {{ $t("inventoryManagement.approval") }}</el-button>
                </el-col> -->
                <!-- <el-col :span="1.5">
                    <el-button size="mini" class="importitemBtn" @click="handleBatch" v-hasPermi="['ny-iqc:inventory:getBatch']"><img src="@/assets/images/icons/batch-inspection.png" alt="" />
                        {{ $t("inventoryManagement.batchInspection") }}</el-button>
                </el-col> -->
                <!-- 取消置顶 -->
                <!-- <el-col :span="1.5">
                    <el-button size="mini" class="topping-Btn" @click="handleTop" v-hasPermi="['ny-iqc:inventory:top']"><img src="@/assets/images/icons/topping.png" alt="" />
                        {{ $t("inventoryManagement.topping") }}</el-button>
                </el-col>-->
                <!-- 导出按钮 移除 -->
                <el-col :span="1.5" >
                    <el-button size="mini" class="exportitemBtn" @click="handleExport" v-hasPermi="['ny-iqc:inventory:export']"><img src="@/assets/images/icons/daochu.png" alt="" />
                        {{ $t("public.export") }}</el-button>
                </el-col>
                <right-toolbar ref="group2" :columns="columns" @callback="columnsCallback"></right-toolbar>
            </el-row>
            <div class="container-table" v-show="selBtn === 1">
                <el-table :height="tableHeight" border stripe :data="groupList" @selection-change="handleSelectionChange">
                    <!-- <el-table-column :label="$t('inventoryManagement.isInspected')" align="left" prop="ifInspect" width="100" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span v-if="parseInt(scope.row.ifInspect) === 1">是</span>
                            <span v-else>否</span>
                        </template>
                    </el-table-column> -->
                    <el-table-column fixed='left' :label="$t('inventoryManagement.materialNo')" align="left" prop="materialCode" width="150" :show-overflow-tooltip="true" />
                    <el-table-column fixed='left' :label="$t('inventoryManagement.materialName')" align="left" minWidth="170" prop="materialName" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.supplierBatchNo')" align="left" prop="lichn" minWidth="110" />
                    <!-- <el-table-column :label="$t('inventoryManagement.materialDocument')" align="left" prop="mblnr" :show-overflow-tooltip="true" /> -->
                    <!-- <el-table-column :label="$t('inventoryManagement.inspectionBatchNo')" align="left" prop="inspectionLotMark" :show-overflow-tooltip="true" /> -->
                    <el-table-column :label="$t('inventoryManagement.batchQuantityTotal')" width="90" align="left" prop="losmengeAll" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.unit')" align="center" prop="mengeneinh" width="70" />
                    <!-- <el-table-column :label="$t('inventoryManagement.purchase')" align="left" prop="eknam" :show-overflow-tooltip="true" /> -->
                    <!-- <el-table-column :label="$t('inventoryManagement.requisitioner')" align="left" prop="requisitioner" :show-overflow-tooltip="true" /> -->

                    <!-- <el-table-column :label="$t('inventoryManagement.supplierName')" align="left" prop="supplierName" minWidth="120" :show-overflow-tooltip="true" /> -->
                    <el-table-column :label="$t('inventoryManagement.supplierNo')" align="left" prop="supplierCode" width="110" :show-overflow-tooltip="true" />
                    <!-- <el-table-column :label="$t('inventoryManagement.purchaseDocument')" align="left" prop="ebeln" minWidth="120" :show-overflow-tooltip="true" /> -->
                    <!-- <el-table-column :label="$t('inventoryManagement.arrivalTime')" align="left" prop="cpudt" minWidth="160" :show-overflow-tooltip="true" /> -->
                    <el-table-column :label="$t('inventoryManagement.fastArriveTime')" align="left" prop="createTime" minWidth="100" :show-overflow-tooltip="true" />

                    <el-table-column  :label="$t('public.opera')" align="center" width="100">
                        <template slot-scope="scope">
                            <div class="action-wrap">
                                <!-- <table-body-btn type="delete" @click.native="handleDelete(scope.row)"    v-hasPermi="['system:message:remove']"/> -->
                                <table-body-btn type="gwedit" @click.native="handleEdit(scope.row)" />
                            </div>
                        </template>
                    </el-table-column>
                </el-table>

                <pagination v-show="groupTotal > 0" :total="groupTotal" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getGroupList" layout="total, sizes, prev, pager, next, jumper" />
            </div>

            <div class="container-table" v-show="selBtn === 2">
                <el-table :height="tableHeight" ref="multipleTable" border :data="detailList" :key="inventoryKey" @selection-change="handleSelectionDetailChange" :row-class-name="tableRowClassName" :row-style="rowStyle">
                    <el-table-column type="selection" width="55" align="center" fixed="left" />
                    <template>
                    <!-- 物料编码，物料名称，供应商名称，批次号，批数量，是否免检，物料状态（试验、试用、试投），厂区，检验批号，到货日期，报检日期，单位，COA，供应商编号，供应商批次号，采购订单号，是否为合格供应商 -->
                    <!-- 到货日期 -->
                    <el-table-column fixed='left' :label="$t('inspectionManagement.cputime')" sortable :min-width="getColumnWidth('cpudt')" align="center" prop="cpudt" :show-overflow-tooltip="true" />
                    <!-- 物料编码 -->
                    <el-table-column fixed='left' :label="$t('inventoryManagement.materialNo')" sortable align="center" :minWidth="getColumnWidth('materialCode')" prop="materialCode" :show-overflow-tooltip="true" />
                    <!-- 物料名称 -->
                    <el-table-column fixed='left' :label="$t('inventoryManagement.materialName')" sortable align="center" :minWidth="getColumnWidth('materialName')" prop="materialName" :show-overflow-tooltip="true" />
                    <!-- 供应商名称 -->
                    <el-table-column :label="$t('inventoryManagement.supplierName')" sortable align="center" :minWidth="getColumnWidth('supplierName')" prop="supplierName" :show-overflow-tooltip="true" />
                    <!-- 批数量 -->
                    <el-table-column :label="$t('inventoryManagement.batchQuantity')" sortable align="center" :min-width="getColumnWidth('batchAmount')" prop="batchAmount" :show-overflow-tooltip="true" />
                    <!-- 批次号 -->
                    <el-table-column :label="$t('inspectionManagement.lichn')" sortable align="center" prop="lot" :minWidth="getColumnWidth('lot')" :show-overflow-tooltip="true" />
                      <!-- 前三批的检验时间 -->
                    <el-table-column :label="$t('inspectionManagement.inspectionTimeForTheFirstThreeBatches')" sortable align="center" 
                    prop="prevDeliveryDate" minWidth="300" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <div class="action-wrap">
                                <!-- <span v-for="(item,i) in getThirtyColos(scope.row.prevDeliveryDate)" :key="i"
                                :style="{color:item.isthirtyDay? 'orange' :'#000'}">
                                  【{{ item.date }}】  
                                </span> prevDeliveryDateList-->
                                <span v-for="(item,i) in scope.row.prevDeliveryDateList" :key="i"  
                                :style="{color:isthirtyDay(item,i,scope.row)? 'orange' :'#000'}">
                                    【{{ item }}】
                                </span>
                            </div>
                        </template>
                    </el-table-column>
                      <!-- 是否免检 -->
                    <!-- <el-table-column :label="$t('inventoryManagement.skipBatchInspection')" sortable align="center" prop="exempted" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <div class="action-wrap">
                                <span v-if="parseInt(scope.row.exempted) === 0" class="labelY">否</span>
                                <span v-if="parseInt(scope.row.exempted) === 1" class="labelY">是</span>
                                <span v-if="parseInt(scope.row.exempted) === 2" class="labelB">审批中</span>
                            </div>
                        </template>
                    </el-table-column> -->
                      <!-- 是否前置检验 -->
                      <el-table-column :label="$t('inventoryManagement.preInspectionOrNot')" sortable  align="center" prop="exempted" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                          <div class="action-wrap">
                            <span v-if="scope.row.art !== '03'" class="labelB">{{$t('public.no')}}</span>
                            <span v-if="scope.row.art === '03'" class="labelY">{{$t('public.yes')}}</span>
                          </div>
                        </template>
                      </el-table-column>
                    <!-- 是否为冲销任务 -->
                      <el-table-column :label="$t('inventoryManagement.IsReversalTask')" sortable  align="center" prop="coverStatusVal" :show-overflow-tooltip="true"/>
                    <!-- 物料状态（试验、试用、试投） 未知 -->
                    <el-table-column :label="$t('material.materialStatus')" sortable align="center" prop="materialTaskStatusVal" :minWidth="getColumnWidth('materialStatus')" :show-overflow-tooltip="true" />
                    <!-- 厂区 -->
                    <el-table-column :label="$t('inventoryManagement.factory')" sortable align="center" prop="factoryName" :min-width="getColumnWidth('factoryName')" :show-overflow-tooltip="true" />
                    <!-- 检验批号 -->
                    <el-table-column :label="$t('inventoryManagement.inspectionBatchNo')" sortable  align="center" prop="inspectionLotMark" :minWidth="getColumnWidth('inspectionLotMark')" :show-overflow-tooltip="true" />

                    <!-- 报检单号 added on 2023-10-30 -->
                    <el-table-column :label="$t('inventoryManagement.splitItemsTbColInspectionCode')" sortable  align="center" prop="inspectionOrder" :minWidth="getColumnWidth('inspectionOrder')" :show-overflow-tooltip="true" />


                    <!-- 报检日期 -->
                    <el-table-column :label="$t('inspectionManagement.deliveryDate')" sortable  align="center" :minWidth="getColumnWidth('deliveryDate')" prop="deliveryDate" :show-overflow-tooltip="true" />
                    <!-- 单位  -->
                    <el-table-column :label="$t('mrbForm.unit')" align="center" prop="mengeneinh" :min-width="getColumnWidth('mengeneinh')" :show-overflow-tooltip="true" />
                    <!-- COA -->
                    <el-table-column :label="$t('inspectionManagement.COA')" sortable :min-width="getColumnWidth('inspectionCoa')" align="center" prop="inspectionCoa" :show-overflow-tooltip="true" >
                        <template slot-scope="scope">
                            <span v-if="scope.row.inspectionCoa==0">OK</span>
                            <span v-if="scope.row.inspectionCoa==1">NG</span>
                            <span v-if="scope.row.inspectionCoa==2">NA</span>
                        </template>
                    </el-table-column>
                    <!-- 供应商编号 -->
                    <el-table-column :label="$t('inventoryManagement.supplierNo')" sortable align="center" prop="supplierCode" :min-width="getColumnWidth('supplierCode')" :show-overflow-tooltip="true" />
                    <!-- 采购订单号 -->
                    <el-table-column :label="$t('inventoryManagement.purchaseDocument')" sortable   align="center" prop="ebeln" :min-width="getColumnWidth('ebeln')" :show-overflow-tooltip="true" />
                      <!-- 采购订单类型 -->
                      <el-table-column :label="$t('inspectionManagement.purchasingOrderType')" sortable align="left" prop="batxt" minWidth="140" :show-overflow-tooltip="true"/>
                      <!-- 是否合批 是否为合格供应商-->
                    <!-- <el-table-column :label="$t('inspectionManagement.isBatch')" sortable align="center" min-width="100" prop="isBatch" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            {{ scope.row.isBatch==1 ? '是' : '否' }}
                        </template>
                    </el-table-column> -->
                    <!-- 是否已检-->
                    <el-table-column :label="$t('inventoryManagement.isInspected')" sortable  align="center" prop="isIncomingInspection" minWidth="100" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span >{{ scope.row.isIncomingInspection == '1'?$t('public.yes'):$t('public.no')}}</span>
                        </template>
                    </el-table-column>
                    <!-- 调拨状态-->
                    <el-table-column label="调拨状态" sortable   align="center"   minWidth="100" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span >{{bsartTXT(scope.row.bsart)}}</span>
                        </template>
                    </el-table-column>
                    </template>

                </el-table>

                <pagination v-show="detailTotal > 0" :total="detailTotal" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getDetailList" layout="total, sizes, prev, pager, next, jumper" />
            </div>

            <!-- 查看 -->
            <el-dialog title="查看" :visible.sync="open" center top="14vh" width="1200px" append-to-body :fullscreen="fullscreen">
                <el-form :model="viewModel" :inline="true" ref="queryForm" label-width="145px">
                    <!-- <el-form-item :label="$t('inventoryManagement.supplierBatchNo')" prop="supplierBatchNo">
                        <el-input v-model="viewModel.supplierBatchNo" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item> -->
                    <el-form-item :label="$t('inventoryManagement.batch')" prop="batch">
                        <el-input v-model="viewModel.batch" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <!-- <el-form-item :label="$t('inventoryManagement.inspectionBatchNo')" prop="inspectionBatchNo">
                        <el-input v-model="viewModel.inspectionBatchNo" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item> -->
                    <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                        <el-input v-model="viewModel.materialName" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialNo">
                        <el-input v-model="viewModel.materialNo" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item :label="$t('inventoryManagement.maturity')" prop="maturity">
                        <el-input v-model="viewModel.maturity" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <!-- <el-form-item label="【SAP】成熟度" prop="sapMaturity">
                        <el-input v-model="viewModel.sapMaturity" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item> -->

                    <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierNo">
                        <el-input v-model="viewModel.supplierNo" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item :label="$t('inventoryManagement.batchQuantityTotal')" prop="batchQuantityTotal">
                        <el-input v-model="viewModel.batchQuantityTotal" clearable disabled size="small" @keyup.enter.native="handleQuery" />
                    </el-form-item>
                    <el-form-item :label="$t('inventoryManagement.inspectionInformation')" prop="inspectionInformation">
                        <el-select v-model="viewModel.inspectionInformation" :placeholder="
                $t('public.select_holder', {
                  select_holder: $t(
                    'inventoryManagement.inspectionInformation'
                  ),
                })
              " style="width: 100%" clearable disabled size="small">
                            <el-option key="0" label="A0" value="0" />
                            <el-option key="1" label="A1" value="1" />
                            <el-option key="2" label="A2" value="2" />
                        </el-select>
                    </el-form-item>
                </el-form>
                <el-table max-height="350" border stripe v-loading="loading" :data="typeList" @selection-change="handleSelectionChange">
                    <el-table-column :label="$t('inventoryManagement.inspectionItems')" align="left" prop="noticeId" minWidth="160" />
                    <el-table-column :label="$t('inventoryManagement.code')" align="left" prop="noticeTitle" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.unit')" align="left" :show-overflow-tooltip="true">
                        <template slot-scope="scope">
                            <span>{{
                scope.row.noticeType == "1"
                  ? $t("message.notice")
                  : $t("message.announcement")
              }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('inventoryManagement.inspectionType')" align="left" prop="hasRead" minWidth="140">
                        <template slot-scope="scope">
                            {{
                scope.row.hasRead == 0
                  ? $t("message.unread")
                  : $t("message.read")
              }}
                        </template>
                    </el-table-column>
                    <el-table-column :label="$t('inventoryManagement.frequency')" align="left" prop="frequency" minWidth="140" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.frequencyValue')" align="left" prop="frequencyValue" minWidth="140" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.samplingScheme')" align="left" prop="samplingScheme" minWidth="140" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.samplingQuantity')" align="left" prop="samplingQuantity" minWidth="140" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.specialCharacteristics')" align="left" prop="specialCharacteristics" minWidth="155" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.inspectionMethod')" align="left" prop="inspectionMethod" minWidth="140" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.decimalPlaces')" align="left" prop="decimalPlaces" minWidth="120" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.targetValue')" align="left" prop="targetValue" minWidth="100" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.lowerValue')" align="left" prop="lowerValue" minWidth="100" :show-overflow-tooltip="true" />
                    <el-table-column :label="$t('inventoryManagement.upperValue')" align="left" prop="upperValue" minWidth="100" :show-overflow-tooltip="true" />
                </el-table>
                <div slot="footer" class="dialog-footer">
                    <el-button icon="el-icon-close" size="mini" @click="open = false" class="drawer-close">{{ $t("public.close") }}</el-button>
                    <!-- <el-button type="primary" @click="submitForm" icon="el-icon-check" size="small">确 定</el-button> -->
                </div>
            </el-dialog>
            <!-- 发起检验 -->
            <el-dialog :title="$t('inventoryManagement.addInspection')" :visible.sync="addInspection" center top="14vh" width="1200px" append-to-body>
                <el-form :model="editModel" :inline="true" ref="editForm" :rules="editFormRules" label-width="145px">
                    <!-- <el-form-item :label="$t('inventoryManagement.supplierBatchNo')" prop="lichn">
                        <el-input v-model="editModel.lichn" clearable disabled size="small" />
                    </el-form-item> -->
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item :label="$t('inspectionManagement.sapBatch')" prop="inspectionLotMark">
                                <el-input v-model="editModel.inspectionLotMark" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.factory')" prop="factoryCode">
                                <el-input v-model="editModel.factoryCode" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.materialName')" prop="materialName">
                                <el-input v-model="editModel.materialName" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>

                    </el-row>

                    <!-- <el-form-item :label="$t('inventoryManagement.inspectionBatchNo')" prop="inspectionLotMark">
                        <el-input v-model="editModel.inspectionLotMark" clearable disabled size="small" />
                    </el-form-item> -->

                    <!-- <el-form-item :label="$t('inventoryManagement.maturity')" prop="maturity">
                        <el-input v-model="editModel.maturity" clearable disabled size="small" />
                    </el-form-item> -->
                    <!-- <el-form-item label="【SAP】成熟度" prop="sapMaturity">
                        <el-input v-model="viewModel.sapMaturity" clearable disabled size="small" />
                    </el-form-item> -->
                    <el-row :gutter="20">

                        <el-col :span=" 8">
                            <el-form-item :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                                <el-input v-model="editModel.materialCode" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.batchQuantityTotal')" prop="batchAmount">
                                <el-input v-model="editModel.batchAmount" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                                <el-input v-model="editModel.supplierCode" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>

                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="8">
                            <el-form-item :label="$t('inspectionManagement.oldBatchQuantity')" prop="batchAmount">
                                <el-input v-model="editModel.batchAmount" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inspectionManagement.oldUnit')" prop="mengeneinh">
                                <el-input v-model="editModel.mengeneinh" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                        <!-- <el-col :span="8">
                            <el-form-item :label="$t('inspectionManagement.reversionBatchQuantity')" prop="amendBatch">
                                <el-input v-model="editModel.amendBatch" @blur="amendBatchBlur(editModel.amendBatch)" clearable size="small" />
                            </el-form-item>
                        </el-col> -->
                        <el-col :span="8">
                            <el-form-item :label="$t('inventoryManagement.skipBatchExemptionFromInspection')" prop="exempted">
                                <el-radio-group v-model="editModel.exempted"  @change="changeExempted"
                                :disabled="taskType==1">
                                    <el-radio label="1">{{ $t("public.yes") }}</el-radio>
                                    <el-radio label="0">{{ $t("public.no") }}</el-radio>
                                </el-radio-group>
                            </el-form-item>
                        </el-col>
                    </el-row>
                    <el-row :gutter="20">
                        <!-- <el-col :span="8">
                            <el-form-item :label="$t('inspectionManagement.reversionUnit')" prop="amendMeng">
                                <el-input v-model="editModel.amendMeng" clearable size="small" />
                            </el-form-item>
                        </el-col> -->

                        <el-col :span="8">
                            <el-form-item :label="$t('inspectionManagement.inspectionPlanVersion')" prop="inspectionPlanVersion" v-if="editModel.exempted!=='1'&&editModel.experimentMaterial!=='1'">
                                <el-select v-model="editModel.version" :placeholder="$t('public.select_holder', {select_holder: $t('inspectionManagement.inspectionPlanVersion'),})" @change="changeVersion" clearable size="small">
                                    <el-option size="mini" v-for="item in versionOptions" :key="item" :label="item" :value="item">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <!-- 当前策略 -->
                            <el-form-item :label="$t('transferRules.currentTactics')" prop="currentTactics" v-if="editModel.exempted!=='1'&&editModel.experimentMaterial!=='1'">
                                <el-select v-model="editModel.currentTactics"  @change="changeCurrentTactics"
                                :placeholder="$t('public.select_holder', {select_holder: $t('transferRules.currentTactics'),})"  clearable size="small" :disabled="taskType==1">
                                    <el-option size="mini" v-for="item in  currentTacticslist" :key="item.value" :label="item.label" :value="item.value">
                                    </el-option>
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="8">
                            <el-form-item :label="$t('inspectionManagement.COA')" prop="inspectionCoa">
                                <el-select v-model="editModel.inspectionCoa"
                                :placeholder="$t('public.select_holder',{select_holder: $t('inspectionManagement.COA')})" style="width:100%;" size="small">
                                    <el-option key="0" label="OK" value="0" />
                                    <el-option key="1" label="NG" value="1" />
                                    <el-option key="NA" label="NA" value="2" />
                                </el-select>
                            </el-form-item>
                        </el-col>
                        <el-col :span="24" >
                            <el-form-item :label="$t('inspectionManagement.COAReportPhotoUpload')"  style="display: flex;">
                                <file-upload v-model="editModel.coaBizType" :otherList="coaBizTypeList"
                                :bizType="'IncomingCoaBizType'"  :bizId="editModel.extraId" ></file-upload>
                                </el-form-item>
                        </el-col>
                    </el-row>

                    <!-- <el-form-item label="卷号" prop="reelNumber">
                        <el-input v-model="editModel.reelNumber" clearable size="small" />
                    </el-form-item> -->

                    <!-- <el-form-item :label="$t('inventoryManagement.isTestMaterial')" prop="experimentMaterial" style="width: 100%">
                        <el-radio-group v-model="editModel.experimentMaterial">
                            <el-radio label="1">{{ $t("public.yes") }}</el-radio>
                            <el-radio label="0">{{ $t("public.no") }}</el-radio>
                        </el-radio-group>
                    </el-form-item> -->
                    <!-- <el-form-item :label="$t('inventoryManagement.recheckSheet')" prop="isRecheck" style="width: 100%">
                        <el-radio-group v-model="editModel.isRecheck" disabled>
                            <el-radio label="1">{{ $t("public.yes") }}</el-radio>
                            <el-radio label="0">{{ $t("public.no") }}</el-radio>
                        </el-radio-group>
                    </el-form-item> -->
                    <el-row :gutter="20">
                        <el-col :span="24">
                            <div v-if="editModel.exempted!=='1'&&editModel.experimentMaterial!=='1'">
                                <inspection-item-info-virtual :isRecheck="editModel.isRecheck === '1'" :isInventory="true" ref="incomingSubmit" :loadings="loadings"
                                :itemData="itemList" :disabled="editModel.isRecheck === '1'?false:true" @callback="submitCallback" :deleteable="true"></inspection-item-info-virtual>
                            </div>
                        </el-col>

                    </el-row>

                    <el-form-item label="旧版本审批人" prop="oldVersion" v-if="editModel.version != versionOptions[versionOptions.length-1]&&editModel.exempted !=='1'">
                        <select-user-dialog v-model="editModel.oldVersion" :multiple="true" @callback="(row) => selectPersion(row)" />
                    </el-form-item>
                    <!-- <el-form-item label="OA审批人" prop="exemptedApprover" v-if="editModel.exempted ==='1'&&!editModel.disabledExempted">
                        <select-user-dialog v-model="editModel.exemptedApprover" />
                    </el-form-item> -->
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitAddForm" :loading="loading" icon="el-icon-check" size="small">{{ $t("public.define") }}</el-button>
                </div>
            </el-dialog>
            <!--split inspection dialog-->
            <el-dialog :title="$t('inventoryManagement.splitInspectionDialogTitle')" @close="closeSplitDialog" :visible.sync="showSplitInspect" center top="14vh" width="800px" append-to-body>
                <el-form :model="currentModel" :inline="true"  ref="splitForm"  label-width="145px">

                    <el-row :gutter="20">
                        <el-col :span="10">
                            <el-form-item :label-width="splitFormLableWith" :label="$t('inventoryManagement.materialNo')" prop="materialCode">
                                <el-input style="width:9rem" v-model="currentModel.materialCode" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                        <el-col :span="12">
                            <el-form-item :label-width="splitFormLableWith" :label="$t('inventoryManagement.materialName')" prop="materialName">
                                <el-input v-model="currentModel.materialName" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>

                    </el-row>

                    <el-row :gutter="20">
                        <el-col :span="10">
                            <el-form-item :label-width="splitFormLableWith" :label="$t('inventoryManagement.supplierNo')" prop="supplierCode">
                                <el-input style="width:9rem" v-model="currentModel.supplierCode" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>
                         <el-col :span="12">
                            <el-form-item :label-width="100" :label="$t('inventoryManagement.supplierName')" prop="supplierName">
                                <el-input v-model="currentModel.supplierName" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>

                    </el-row>
                    <el-row :gutter="20">
                        <el-col :span="10">
                            <el-form-item  :label-width="splitFormLableWith" :label="$t('inspectionManagement.sapBatch')" prop="inspectionLotMark">
                                <el-input style="width:9rem" v-model="currentModel.inspectionLotMark" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>

                        <el-col :span="12">
                            <el-form-item :label-width="splitFormLableWith" :label="$t('inventoryManagement.batchQuantityTotal')" prop="batchAmount">
                                <el-input v-model="currentModel.batchAmount" clearable disabled size="small" />
                            </el-form-item>
                        </el-col>

                    </el-row>
                    <el-row :gutter="24"  style="display:flex;justify-content:flex-start">
                        <el-col  :span="12">

                        <el-form-item   :label-width="splitFormLableWith" :label="$t('inventoryManagement.splitAmount')">
                        <el-input-number size="small"  :min="0.01"  style="width:9rem" v-model="splitAmount" clearable required />
                        <el-button style="margin-left:.625rem" @click="handleAddSplitItem" icon="el-icon-plus"></el-button>
                        </el-form-item>

                        </el-col>
                        <!-- <el-col :span="12" style="background-color:blue">
                            <el-button @click="handleAddSplitItem" icon="el-icon-plus">添加</el-button>
                        </el-col> -->
                    </el-row>


                    <div>

                        <el-card class="box-card" id="fullscreen">

                            <div class="app-container">
                            <el-table border stripe :data="splitItems">
                                <el-table-column :label="$t('inventoryManagement.splitItemsTbColInspectionCode')" align="left" prop="inspectionCode" minWidth="160" />
                                <el-table-column :label="$t('inventoryManagement.splitItemsTbColBatchAmount')" align="left" prop="splitAmount" minWidth="160" />
                                <el-table-column v-if="false" :label="$t('public.opera')" align="left"  minWidth="160" >
                                    <template slot-scope="scope">

                                    <table-body-btn type="delete" @click.native="removeSplitItem(scope.$index)" >删除</table-body-btn>
                                   </template>
                                </el-table-column>

                            </el-table>
                        </div>
                        </el-card>
                    </div>

                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="cancleSplit" icon="el-icon-close" size="small">{{$t('public.cancel')}}</el-button>
                    <el-button type="primary" @click="saveSplit" :loading="loadingSaveSplit" icon="el-icon-check" size="small">{{ $t("inventoryManagement.comfirmSplit") }}</el-button>
                </div>
            </el-dialog>
            <!--end split inspection dialog-->
            <!--start combine dialog-->
            <el-dialog :title="$t('inventoryManagement.combineSplitTitle')"   :visible.sync="showCombine" center top="14vh" width="800px" append-to-body>
                <el-card>
                    <el-row :gutter="24">
                        <!-- 将恢复的报检单号 -->
                        <el-col align="right" :span="5" >{{$t('inventoryManagement.toRecoverInspectionCode')  }} </el-col>
                        <el-col :span="19" style="display:flex;justify-content:flex-start">
                        {{ splitInfo.splitItemsOrderNo }}
                        </el-col>

                    </el-row>
                    <el-row :gutter="24">
                        <!-- 恢复原报检单号 -->
                        <el-col :span="5" align="right">{{$t('inventoryManagement.originalInspectionCode')  }} </el-col>
                        <el-col :span="19" >{{ splitInfo.inspectionBatchCode }}</el-col>
                    </el-row>
                    <el-row :gutter="24">
                        <!-- 恢复数量 -->
                        <el-col :span="5" align="right"> {{$t('inventoryManagement.recoverAmount')  }}</el-col>
                        <el-col :span="19">{{ splitInfo.originalAmmount }}</el-col>
                    </el-row>
                </el-card>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="cancleCombine"  icon="el-icon-close" size="small">{{$t('public.cancel')}}</el-button>
                    <el-button type="primary" @click="combineSplit" :loading="loadingRecover" icon="el-icon-check" size="small">{{ $t("inventoryManagement.comfirmRecover") }}</el-button>
                </div>
            </el-dialog>
             <!--end combine dialog-->
            <!-- 审批 -->
            <el-dialog :title="$t('inventoryManagement.approval')" append-to-body :visible.sync="approvalOpen" center top="14vh" width="500px" :fullscreen="fullscreen">
                <el-form :model="approvalForm" ref="approvalForm" label-position="top" :rules="approveRules">
                    <el-form-item :label="$t('inventoryManagement.isPassApproval')" prop="approveStatus">
                        <el-radio-group v-model="approvalForm.approveStatus" @change="radioChange">
                            <el-radio label="0">{{
                $t("inventoryManagement.pass")
              }}</el-radio>
                            <el-radio label="1">{{
                $t("inventoryManagement.reject")
              }}</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <!-- <el-form-item :label="$t('inventoryManagement.rejectReason')" prop="supplierBatchNo">
                        <el-popover placement="right" width="400" trigger="click">
                            <el-table :data="tipsData" :show-header="false" @row-click="tipsClick">
                                <el-table-column property="title" label="建议" :show-overflow-tooltip="true"></el-table-column>
                            </el-table>
                            <el-input type="textarea" slot="reference" :placeholder="
                $t('public.placeholder', {
                  placeholder: $t('inventoryManagement.rejectReason'),
                })
              " v-model="approvalForm.rejectReason" maxlength="1000">
                            </el-input>
                        </el-popover>

                    </el-form-item> -->
                    <el-form-item :label="$t('inventoryManagement.notifier')" prop="informPeoplesName" v-if="approvalForm.approveStatus==='1'">
                        <select-user-dialog :multiple="true" v-model="approvalForm.informPeoplesName" @callback="(row) => userDataCallback(row)" />
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitApproval" icon="el-icon-check" size="small">{{ $t("public.define") }}</el-button>
                </div>
            </el-dialog>

            <el-drawer :with-header="false" :visible.sync="drawer" size="70%" :direction="direction" :before-close="handleClose">
                <div class="app-container">
                    <div class="container-header">
                        <div class="header-left">
                            {{ $t("inventoryManagement.editInspection") }}
                        </div>
                    </div>
                    <el-row :gutter="10" class="mb8">
                        <el-col :span="1.5">
                            <el-button type="primary" icon="el-icon-plus" size="mini" @click="groupHandleAdd" v-hasPermi="['ny-iqc:inventory:getCheckoutEcho']">{{ $t("inventoryManagement.addInspection") }}</el-button>
                        </el-col>

                        <!-- <el-col :span="1.5">
                            <el-button type="primary" icon="el-icon-edit-outline" size="mini" @click="handleApproval" v-hasPermi="['ny-iqc:inventory:approve']">{{ $t("inventoryManagement.approval") }}</el-button>
                        </el-col> -->
                    </el-row>
                    <div class="container-table">
                        <el-table max-height="350" border stripe v-loading="loading" :data="drawerList" @selection-change="handleSelectionChange">
                            <el-table-column type="selection" width="55" align="center" />
                            <el-table-column :label="$t('inspectionManagement.lot')" align="left" prop="lot" min-width="120" />
                            <el-table-column :label="$t('inventoryManagement.inspectionBatchNo')" align="left" prop="inspectionLotMark" min-width="120" />
                            <!-- <el-table-column :label="$t('inventoryManagement.inspectionBatchNo')" minWidth="120" align="left" prop="inspectionLotMark" /> -->
                            <!-- <el-table-column :label="$t('inventoryManagement.approvalStatus')" align="left" prop="approveStatus" :show-overflow-tooltip="true">
                                <template slot-scope="scope">
                                    <div>
                                        <el-tag size="small" :type="formatStatus(scope.row.approveStatus)">{{ formatStatusLabel(scope.row.approveStatus) }}</el-tag>
                                    </div>
                                </template>
                            </el-table-column> -->
<!--                            <el-table-column :label="$t('inventoryManagement.approvalTime')" show-overflow-tooltip align="left" prop="approveTime" minWidth="160" />-->
                            <el-table-column :label="$t('inventoryManagement.materialNo')" show-overflow-tooltip align="left" prop="materialCode" minWidth="160" />
                            <el-table-column :label="$t('inventoryManagement.unit')" show-overflow-tooltipalign="left" prop="mengeneinh" />
                            <el-table-column :label="$t('inspectionManagement.batchNum')" align="left" prop="batchAmount" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inventoryManagement.factory')" align="left" prop="factoryName" min-width="180" :show-overflow-tooltip="true" />
<!--                            <el-table-column :label="$t('inventoryManagement.recheckSheet')" minWidth="120" align="left" prop="isRecheck" :show-overflow-tooltip="true">
                                <template slot-scope="scope">
                                    <div>
                                        <span v-if="parseInt(scope.row.isRecheck) > 0">{{
                                            $t("public.yes")
                                          }}</span>
                                        <span v-else>{{ $t("public.no") }}</span>
                                    </div>
                                </template>
                            </el-table-column>-->
                            <!--
                            <el-table-column :label="$t('inventoryManagement.rejectReason')" align="left" prop="rejectReason" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inventoryManagement.factory')" align="left" prop="factoryName" :show-overflow-tooltip="true" />
                            <el-table-column :label="$t('inventoryManagement.location')" align="left" prop="locationName" :show-overflow-tooltip="true" />

                            <el-table-column :label="$t('inventoryManagement.oldVersionStatus')" align="left" prop="oldVersionStatus" :show-overflow-tooltip="true">
                                <template slot-scope="scope">
                                    <div>
                                        <el-tag size="small" :type="formatStatus(scope.row.oldVersionStatus)">{{
                        formatStatusLabel(scope.row.oldVersionStatus)
                      }}</el-tag>
                                    </div>
                                </template>
                            </el-table-column> -->

                            <!-- <el-table-column :label="$t('inventoryManagement.inspectionOrderstatus')" align="left" prop="inspectionOrderstatus" minWidth="120"  :show-overflow-tooltip="true"/> -->
                        </el-table>
                    </div>
                </div>
                <div class="drawer-footer">
                    <el-button icon="el-icon-close" size="mini" @click="drawerClose" class="drawer-close">{{ $t("public.close") }}</el-button>
                </div>
            </el-drawer>

            <el-dialog title="批量检验" :visible.sync="batchOpen" center top="14vh" width="500px" append-to-body :fullscreen="fullscreen">
                <el-form :model="approvalForm" ref="approvalForm" label-position="top" :rules="approveRules">
                    <el-form-item label="送检批次号" prop="exempted">
                        <el-input v-model="names" disabled size="small" />
                    </el-form-item>
                    <!-- <el-form-item label="是否免检" prop="exempted">
                        <el-radio-group v-model="batchModel.exempted" @change="radioChange">
                            <el-radio label="1">是</el-radio>
                            <el-radio label="0">否</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <el-form-item label="OA审批人" prop="exemptedApprover" v-if="batchModel.exempted==='1'">
                        <select-user-dialog v-model="batchModel.exemptedApprover" />
                    </el-form-item> -->
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitBatch" icon="el-icon-check" size="small">{{ $t("public.define") }}</el-button>
                </div>
            </el-dialog>
        </div>
    </list-layout>
</template>

<script>
import {getType, refreshCache} from '@/api/basic/dict/type'
import {
  approveCheck,
  checkoutIncoming,
  getBatch,
  getInspectionCheck,
  inventoryApprove,
  inventoryTop,
  listInventory,
  listInventoryGroup,
  splitInspection,
  getSplitItemsInfo,
  recoverSplit
} from '@/api/inventoryManagement/inspectedInventory'
import {getAllVersion, getPlanItem,} from '@/api/inspectionManagement/inspectionManagement'
import {listProject} from '@/api/basic/project'
import {listCheckoutUnit} from '@/api/basic/checkoutUnit'
import SelectUserDialog from '@/views/components/SelectUserDialog'
import FactoryDialog from '@/views/components/FactoryDialog'
import InspectionItemInfoVirtual from '@/views/components/InspectionItemInfoVirtual'
import {listAllFactory} from '@/api/basic/factory'
import {mapState} from 'vuex'
import {geFileByBiz} from '@/api/file/file'
import { undoToDo } from "@/api/notificationManager/notificationManager"
import {carryOutList} from "@/api/inspectionManagement/transferRules"
export default {
    name: 'inspectedInventory',
    dicts: [
        'NYIQC_SHEET_STATUS', //检验单状态
        'NYIQC_NCR_DECISION', //使用决策
        'NYIQC_RULE_TACTICS'
    ],
    components: {
        SelectUserDialog,
        FactoryDialog,
        InspectionItemInfoVirtual,
    },
    computed: {
        ...mapState({
            isFold: (state) => state.app.isFold,
        }),
    },
    watch: {
        isFold(val) {
            if (val === true) {
                this.tableHeight = 'calc(100vh - 308px)'
            } else {
                this.tableHeight = 'calc(100vh - 446px)'
            }
        },
    },
    data() {
      return {
            currentTacticslist:[],
            coaBizTypeList:[],
            loadingSaveSplit: false,
            loadingRecover: false,
            loadingSplitInfo: false,
            splitInfo:{},
            showCombine:false,
            splitAmount:50,
            splitFormLableWith:120,
            splitItems:[],//split items, show in split inspection dialog
            showSplitInspect:false,//show or hide  split inspection window
            tipsData: [],
            batchModel: {
                exempted: '0',
                exemptedApprover: null,
            },
            batchOpen: false,
            factoryList: [],
            columns: [
                {
                    key: 0,
                    label: '检验单号',
                    visible: true,
                },
                {
                    key: 1,
                    label: this.$t('inventoryManagement.recheckSheet'),
                    visible: true,
                },
                {
                    key: 2,
                    label: this.$t('inventoryManagement.isInspected'),
                    visible: true,
                },

                {
                    key: 3,
                    label: this.$t('inventoryManagement.arrivalTime'),
                    visible: true,
                },
                {
                    key: 4,
                    label: this.$t('inventoryManagement.approvalStatus'),
                    visible: true,
                },
                {
                    key: 5,
                    label: this.$t('inventoryManagement.approvalTime'),
                    visible: true,
                },
                {
                    key: 6,
                    label: this.$t('inventoryManagement.rejectReason'),
                    visible: true,
                },
                {
                    key: 7,
                    label: this.$t('inventoryManagement.materialNo'),
                    visible: true,
                },
                {
                    key: 8,
                    label: this.$t('inventoryManagement.materialName'),
                    visible: true,
                },
                {
                    key: 9,
                    label: '规格型号',
                    visible: true,
                },
                {
                    key: 9,
                    label: '【SAP】成熟度',
                    visible: true,
                },
                {
                    key: 10,
                    label: this.$t('inventoryManagement.maturity'),
                    visible: true,
                },
                {
                    key: 11,
                    label: this.$t('inventoryManagement.batch'),
                    visible: true,
                },
                {
                    key: 12,
                    label: this.$t('inventoryManagement.incomingQuantity'),
                    visible: true,
                },
                {
                    key: 13,
                    label: this.$t('inventoryManagement.unit'),
                    visible: true,
                },
                {
                    key: 14,
                    label: this.$t('inventoryManagement.inspectionBatchNo'),
                    visible: true,
                },
                {
                    key: 15,
                    label: this.$t('inventoryManagement.purchase'),
                    visible: true,
                },
                {
                    key: 16,
                    label: this.$t('inventoryManagement.supplierName'),
                    visible: true,
                },
                {
                    key: 17,
                    label: this.$t('inventoryManagement.supplierNo'),
                    visible: true,
                },
                {
                    key: 18,
                    label: this.$t('inventoryManagement.purchaseDocument'),
                    visible: true,
                },
                {
                    key: 19,
                    label: this.$t('inventoryManagement.factory'),
                    visible: true,
                },
                {
                    key: 20,
                    label: this.$t('inventoryManagement.location'),
                    visible: true,
                },
                {
                    key: 21,
                    label: this.$t('public.createTime'),
                    visible: true,
                },
                {
                    key: 22,
                    label: this.$t('inventoryManagement.isIncomingInspection'),
                    visible: true,
                },
            ],
            approvalRules: {
                informPeoplesName: [
                    {
                        required: true,
                        trigger: 'change',
                        message: '请选择通知人',
                    },
                ],
            },
            inventoryKey: 0,
            tableHeight: 'calc(100vh - 308px)',
            direction: 'rtl',
            showSearch: true,
            addInspection: false,
            projectList: [],
            unitList: [],
            drawer: false,
            approvalOpen: false,
            viewModel: {
                inspectionInformation: '0',
            },
            editModel: {
                approveStatus: '0',
                exempted: '0',
                isRecheck: '0',
                experimentMaterial: '0',
            },
            approvalForm: {
                approveStatus: '0',
                informPeoplesName: null,
                rejectReason: null,
                informPeoples: null,
            },
            frequencyOptions: [
                {
                    value: '批',
                    label: '批',
                },
                {
                    value: '件',
                    label: '件',
                },
                {
                    value: '年',
                    label: '年',
                },
                {
                    value: '季',
                    label: '季',
                },
                {
                    value: '月',
                    label: '月',
                },
                {
                    value: '日',
                    label: '日',
                },
            ],
            samplingSchemeOptions: [
                {
                    value: 'GB/T2828.1-2012',
                    label: 'GB/T2828.1-2012',
                },
                {
                    value: '百分比',
                    label: '百分比',
                },
                {
                    value: '固定抽样',
                    label: '固定抽样',
                },
                {
                    value: 'C=0',
                    label: 'C=0',
                },
            ],
            testMethodOptions: [
                {
                    value: '目测',
                    label: '目测',
                },
                {
                    value: '量具',
                    label: '量具',
                },
                {
                    value: '验证',
                    label: '验证',
                },
                {
                    value: 'ny-iqc作业指导书',
                    label: 'ny-iqc作业指导书',
                },
                {
                    value: '核对COA',
                    label: '核对COA',
                },
            ],
            samplingLevelOptions: [
                {
                    value: 'S-1',
                    label: 'S-1',
                },
                {
                    value: 'S-2',
                    label: 'S-2',
                },
                {
                    value: 'S-3',
                    label: 'S-3',
                },
                {
                    value: 'S-4',
                    label: 'S-4',
                },
                {
                    value: 'Ⅰ',
                    label: 'Ⅰ',
                },
                {
                    value: 'Ⅱ',
                    label: 'Ⅱ',
                },
                {
                    value: 'Ⅲ',
                    label: 'Ⅲ',
                },
            ],
            samplingMethodCOptions: [
                {
                    value: '0.01',
                    label: '0.01',
                },
                {
                    value: '0.015',
                    label: '0.015',
                },
                {
                    value: '0.025',
                    label: '0.025',
                },
                {
                    value: '0.04',
                    label: '0.04',
                },
                {
                    value: '0.1',
                    label: '0.1',
                },
                {
                    value: '0.15',
                    label: '0.15',
                },
                {
                    value: '0.25',
                    label: '0.25',
                },
                {
                    value: '0.4',
                    label: '0.4',
                },
                {
                    value: '0.65',
                    label: '0.65',
                },
                {
                    value: '1',
                    label: '1',
                },
                {
                    value: '1.5',
                    label: '1.5',
                },
                {
                    value: '4',
                    label: '4',
                },
                {
                    value: '6.5',
                    label: '6.5',
                },
                {
                    value: '10',
                    label: '10',
                },
            ],
            samplingLevelTypeOptions: [
                {
                    value: '正常',
                    label: '正常',
                },
                {
                    value: '放宽',
                    label: '放宽',
                },
                {
                    value: '加严',
                    label: '加严',
                },
            ],
            samplingFixedTypeOptions: [
                {
                    value: '批',
                    label: '批',
                },
                {
                    value: '件',
                    label: '件',
                },
            ],
            specialCharacteristicsOptions: [
                {
                    value: '空',
                    label: '空',
                },
                {
                    value: 'CC',
                    label: 'CC',
                },
                {
                    value: 'SC',
                    label: 'SC',
                },
            ],
            versionOptions: [],
            selectRows: [],
            selBtn: 2,
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            maturityOptions: [],
            // 字典表格数据
            typeList: [],
            itemList: [],
            groupList: [],
            drawerList: [],
            detailList: [],
            detailTotal: 0,
            drawerTotal: 0,
            groupTotal: 0,
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 日期范围
            dateRange: [],
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 20,
                factoryCode: undefined,
                factoryName: undefined,
                inspectionLotMark: null,
                lichn: undefined,
                lot: undefined,
                materialName: undefined,
                materialCode: undefined,
                dataSource: undefined,
                supplierCode: undefined,
                sheetStatus: undefined,
                approveStatus: undefined,
                isIncomingInspection: '0',
               // cpudt: [],
              // params: {}//,disabled by zhongweidao
              //by zhongweidao
              params:[]// to store arrived date range begin is at index 0
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {
                exemptedApprover: [
                    {
                        required: true,
                        message: '审批人不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            approveRules: {
                informPeoplesName: [
                    {
                        required: true,
                        message: '请选择通知人',
                        trigger: 'change',
                    },
                ],
            },
            editFormRules: {
                oldVersion: [
                    {
                        required: true,
                        message: '请选择审批人',
                        trigger: 'change',
                    },
                ],
                exemptedApprover: [
                    {
                        required: true,
                        message: '审批人不能为空',
                        trigger: 'blur',
                    },
                ],
            },
            fullscreen: false,
            currentModel: {},
            names: [],
            loadings:false,
            thirtyDaysAgoTimestamp:2592000000,
            taskType:"0"
        }
    },
  created() {
    let id = this.$route.query.id;
    let scene = this.$route.query.scene;
    //回调调用 OA待办转已办 接口
    if (id != undefined && scene != undefined) {
      undoToDo(id, scene).then((res) => {
        if (res.code != 200) {
          this.$modal.msgError(res.msg)
        }
      })
      this.queryParams.id = id
    }
     
  },
    mounted() {
        let inventoryColumns = JSON.parse(
            localStorage.getItem('inventoryColumns')
        )
        let tipsData = JSON.parse(localStorage.getItem('tipsData'))
        this.tipsData = tipsData ? tipsData : []
        if (inventoryColumns) {
            this.columns = inventoryColumns
        }
        console.log(this.$route)
        if (this.$route.query.status) {
            this.queryParams.approveStatus = this.$route.query.status
            // if (this.$route.query.ncr) {
            //     this.queryParams.todayTime = this.getNowDate()
            // }
        }
        if (this.$route.query.uniqueId) {
            this.queryParams.id = this.$route.query.uniqueId
        }
        console.log('isFold', this.isFold)

        this.getDetailList()
        this.getProjectList()
        this.getUnitList()
        this.getFactoryList()
    },
    activated() {
        if (this.$route.query.status) {
            this.queryParams.approveStatus = this.$route.query.status
            // if (this.$route.query.ncr) {
            //     this.queryParams.todayTime = this.getNowDate()
            // }
        }
        if (this.$route.query.uniqueId) {
            this.queryParams.id = this.$route.query.uniqueId
        }
        console.log('isFold', this.isFold)

        this.getDetailList()
        this.getProjectList()
        this.getUnitList()
        this.getFactoryList()
    },
    methods: {
        
    bsartTXT(txt){
        var arr=['A013','A023','A024', 'A029', 'A030', 'A031','A032']
        if(txt){
            return arr.includes(txt) ? this.$t('nyiqc.Notinspectedallot') :this.$t('nyiqc.Regularorder')
        }else{
            return this.$t('nyiqc.Regularorder')
        }
    },
    getThirtyColos(time){
        var arr=time?.split("、")
        
        var newDate=[]
        for (const key in arr) {
            newDate.push({
                date:arr[key],
                isthirtyDay:(new Date(arr[key])).getTime() < this.thirtyDaysAgoTimestamp
            })
        }

       return newDate
    },
    isthirtyDay(item,i,row){
        // var test=24 * 60 * 60 * 1000-11
        var list=row.prevDeliveryDateList
        var deliveryDate=row.deliveryDate
        if(i===0){
            // 如果 第1个值时间戳 大于 第2个时间戳+30天时间戳
            return (new Date(deliveryDate)).getTime() > (new Date(item)).getTime()+ this.thirtyDaysAgoTimestamp
        }else if(i==1){
            // 如果 第1个值时间戳 大于 第2个时间戳+30天时间戳
            return (new Date(list[0])).getTime() > (new Date(item)).getTime()+ this.thirtyDaysAgoTimestamp
        }else if(i==2){
            return (new Date(list[1])).getTime() >  (new Date(item)).getTime()+ this.thirtyDaysAgoTimestamp
        }else{
            return ''
        }
        
    },
      getColumnWidth(columnName) {
        const data = this.detailList;
        const getTextWidth = (text) => {
          const canvas = document.createElement("canvas");
          const context = canvas.getContext("2d");
          context.font = "14px Arial"; // 设置字体大小和类型
          return context.measureText(text).width;
        };

        const columnValues = data.map((item) => item[columnName]);
        var maxTextWidth = Math.max(...columnValues.map(getTextWidth));
        if (columnValues[0] == undefined) {
          maxTextWidth = 150 //给默认表格宽度
        }
        return maxTextWidth*1.5;
      },
        changeExempted(e){
            if(e==1) return
            this.loadings=true
            getAllVersion({ ids: this.ids.join(','), exempted:this.editModel.exempted,taskType:this.taskType}).then(
                (result) => {

                    let versions = result.data.params?.VERSION
                        ? result.data.params.VERSION.split(',')
                        : []

                    getPlanItem({
                        amendBatch: '',
                        batchAmount: this.selectRows[0].batchAmount,
                        factoryCode:this.editModel.factoryCode,
                        materialCode:this.editModel.materialCode,
                        supplierCode:this.editModel.supplierCode,
                        version: versions[versions.length - 1],
                        samplingType:result.data.samplingType
                    }).then((res) => {
                        this.itemList = res.data
                        this.loadings=false
                    })
                    this.versionOptions = versions
                    this.editModel.version=  result.data.params?.VERSION
                }
            )
        },
        getFactoryList() {
            listAllFactory().then((res) => {
                this.factoryList = res.data
            })
        },
        rowStyle({ row, rowIndex }) {
            let styleObj = {}
            if (row.sort == '1') {
                styleObj.backgroundColor = '#ffd0d0'
                return styleObj
            }
        },
        tipsClick(row) {
            this.approvalForm.rejectReason = row.title
        },
        columnsCallback(inventoryColumns) {
            console.log('inventoryColumns', inventoryColumns)
            localStorage.setItem(
                'inventoryColumns',
                JSON.stringify(inventoryColumns)
            )
            this.inventoryKey++
        },
        radioChange() {
            this.approvalForm.informPeoplesName = null
            this.approvalForm.informPeoples = null
        },
        getNowDate() {
            var date = new Date()
            var y = date.getFullYear()
            var m = date.getMonth() + 1
            var d = date.getDate()
            //  当前日期
            return (
                y + '-' + (m < 10 ? '0' + m : m) + '-' + (d < 10 ? '0' + d : d)
            )
        },
        formatOrderStatus(e) {
            if (e) {
                let obj = this.dict.type.NYIQC_SHEET_STATUS.find((item) => {
                    return item.value === e
                })
                console.log(e)
                return obj.label
            } else {
                return ''
            }
        },
        submitBatch() {
            this.batchOpen = false
            getBatch({ ...this.batchModel, ids: this.ids.join(',') }).then(
                (response) => {
                    if (response.code == 200) {
                        this.$modal.msgSuccess(response.msg)
                        if (this.selBtn === 1) {
                            this.getGroupList()
                        } else {
                            this.getDetailList()
                        }
                    }
                }
            )
        },
        handleBatch() {
            if (this.selectRows.length === 0) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            this.names = this.selectRows.map((item) => item.inspectionLotMark)
            this.batchOpen = true
            // const names = this.selectRows.map((item) => item.inspectionLotMark)
            // this.$modal
            //     .confirm('是否对检验批次号为"' + names + '"的数据发起批量检验?')
            //     .then(() => {
            //         getBatch({ ids: this.ids.join(',') }).then((response) => {
            //             if (response.code == 200) {
            //                 this.$modal.msgSuccess(response.msg)
            //                 if (this.selBtn === 1) {
            //                     this.getGroupList()
            //                 } else {
            //                     this.getDetailList()
            //                 }
            //             }
            //         })
            //     })
        },
        formatStatus(status) {
            switch (status) {
                case '0':
                    return 'success'
                case '1':
                    return 'danger'
                default:
                    return 'info'
            }
        },
        formatStatusLabel(status) {
            switch (status) {
                case '0':
                    return '通过'
                case '1':
                    return '不通过'
                default:
                    return '未审批'
            }
        },
        drawerClose() {
            this.drawer = false
        },
        changeSampling(e, scope) {
            this.itemList[scope.$index].samplingTwo = null
            this.itemList[scope.$index].samplingThree = null
        },
        userDataCallback(userId) {
            this.approvalForm.informPeoples = userId
            this.$refs.approvalForm.validateField('informPeoplesName')
        },
        selectPersion(row) {
            // this.editModel.oldVersion = row
            this.$refs['editForm'].clearValidate()
        },
        changeBtn(type) {
            this.selBtn = type
            if (type === 1) {
                this.getGroupList()
            } else {
                this.getDetailList()
            }
        },
        changeProject(e) {
            let obj = this.projectList.find((item) => {
                return item.projectName === e.row.projectName
            })
        },
        getUnitList() {
            listCheckoutUnit().then((res) => {
                this.unitList = res.rows
            })
        },
        getProjectList() {
            listProject().then((res) => {
                this.projectList = res.rows
            })
        },
        /** 查询字典类型列表 */
        getGroupList() {
            this.loading = true
            let params = { ...this.queryParams }
            /*

            //it's no use
            if (params.cpudt.length) {
                params.params.beginTime = params.cpudt[0]
                params.params.endTime = params.cpudt[1]
            } else {
                params.params.beginTime = ''
                params.params.endTime = ''
            }
            delete params.cpudt
             //*/
            let dateRange={};
            dateRange["beginTime"]=this.queryParams.params[0];
            dateRange["endTime"]=this.queryParams.params[1];
            params.params=dateRange;
            listInventoryGroup(params).then((response) => {
                if (response.code == 200 && response.rows) {
                    this.groupList = response.rows
                    this.groupTotal = response.total
                    this.loading = false
                    this.tableHeight = this.isFold
                        ? 'calc(100vh - 308px)'
                        : 'calc(100vh - 446px)'
                }
            })
        },
        getDetailList() {
            //debugger;
            this.loading = true
            let params = { ...this.queryParams }
            /*
            //it's no use
            if (params.cpudt.length) {
                params.params.beginTime = params.cpudt[0]
                params.params.endTime = params.cpudt[1]
            } else {
                params.params.beginTime = ''
                params.params.endTime = ''
            }
            delete params.cpudt
            //*/
            let dateRange={};
            dateRange["beginTime"]=this.queryParams.params[0];
            dateRange["endTime"]=this.queryParams.params[1];
            params.params=dateRange;
           console.log('data:',params);
            listInventory(params).then((response) => {
                if (response.code == 200 && response.rows) {
                    let selectRows = [...this.selectRows]
                    this.detailList = response.rows
                    // console.log(
                    //     '111selectRows==============================',
                    //     selectRows
                    // )
                    if (selectRows.length > 0) {
                        setTimeout(() => {
                            this.detailList.forEach((io) => {
                                selectRows.forEach((ko) => {
                                    console.log(
                                        'true=============================='
                                    )
                                    if (io.id === ko.id) {
                                        this.$refs.multipleTable.toggleRowSelection(
                                            io,
                                            true
                                        )
                                    }
                                })
                            })
                        }, 300)
                    }
                    this.detailTotal = response.total
                    this.loading = false
                    this.tableHeight = this.isFold
                        ? 'calc(100vh - 308px)'
                        : 'calc(100vh - 446px)'
                }
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            dictId: undefined,
                (this.form = {
                    dictName: undefined,
                    dictType: undefined,
                    status: '0',
                    remark: undefined,
                })

            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
           // debugger ;
            this.queryParams.pageNum = 1
            if (this.selBtn === 1) {
                this.getGroupList()
            } else {
                this.getDetailList()
            }
        },
        searchQuery() {
            this.queryParams.pageNum = 1
            if (this.selBtn === 1) {
                this.getGroupList()
            } else {
                this.getDetailList()
            }
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.dateRange = []
            this.queryParams.id = null
            this.queryParams.todayTime = null
            this.queryParams.factoryName = null
            this.resetForm('queryForm')
            this.searchQuery()
        },
        /** 新增按钮操作 */
        handleAdd() {
            if (this.ids.length === 0) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            this.addInspection = true
        },
        /*
          start split inspection logic
         */
         openCombine(){
            if (this.ids.length !== 1) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return false;
            }
            if(!this.isSplitInspection(this.selectRows[0]))
            {
                this.$modal.msgWarning(
                    this.$t('inventoryManagement.selectSplitItemWarning')
                )
                return false;
            }
            const id=this.selectRows[0].id;
            try
            {
              //  console.log('..............................')

            getSplitItemsInfo(id).then(res=>{
                if(res.code==200)
                {
                    //this.$modal.msgSuccess(this$t("inventoryManagement.comineSucc"));

                    this.splitInfo.id=res.data.id;
                    //The joint string of split items inpsection code
                    this.splitInfo.splitItemsOrderNo=res.data.childInspectionOrder;
                    //The order no of paraent
                    this.splitInfo.inspectionBatchCode=res.data.inspectionOrder;
                    this.splitInfo.originalAmmount=res.data.batchAmount;
                    this.showCombine=true;
                }
                else{
                    this.$modal.msgError(res.msg);
                }
            });
        }
        catch(e)
        {
            console.error(e);
        }
         },
         cancleCombine(){
            this.showCombine=false;
         },
         combineSplit(){
            const id=this.splitInfo.id;
            //console.log('recover id:',id);
           this.loadingRecover = true;
           recoverSplit(id).then(res => {
             this.loadingRecover = false
             if (res.code == 200) {
               this.$modal.msgSuccess(this.$t("inventoryManagement.comineSucc"));
               this.getDetailList();
               this.showCombine = false;
             }
             else {
               this.$modal.msgError(res.msg);
             }
           }).finally(() => this.loadingRecover = false);

         },
         removeSplitItem(index){
            //this.splitItems.remove
            this.splitItems.splice(index,1);
         },
        isSplitInspection(row)
        {
            if(this.selectRows[0].parentExtraId)
            {
                return true;
            }
            return false;
        },
        /**
         * Validate that only one row is selcted
         * and which is not split yet
         */
        validateSelection(){
            if (this.ids.length !== 1) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return false;
            }
         //   console.log('this.selectRows[0].parentExtraId:::::::::',this.selectRows[0].parentExtraId)
            if(this.isSplitInspection(this.selectRows[0]))
            {
                this.$modal.msgWarning(
                    this.$t('inventoryManagement.warningSelectNotSplit')
                )
                return false;
            }
            this.currentModel = this.selectRows[0];//set selected row data
            console.log('model:::',this.currentModel);
            return true;
        },
        //
        validateAmount(addAmount){
            //debugger;
            let currentAmmount=0.0;
            this.splitItems.forEach(item=>{
                currentAmmount+=item.splitAmount;
            })
            const left=this.currentModel.batchAmount-currentAmmount;
            if(left<addAmount)
            {
                this.$modal.msgError(this.$t("inventoryManagement.splitAmountLeftWarning")+left);
                return false;
            }
            return true;
        },
        //add split item to talbe
        handleAddSplitItem(){
           // var
           if(this.validateAmount(this.splitAmount))
           {
            const index=this.splitItems.length+1;
             const item= {
                            inspectionCode: this.currentModel.inspectionOrder+'-'+index,
                            splitAmount:this.splitAmount
              }
            this.splitItems.push(item);
           }
        },
        closeSplitDialog(){
            this.splitItems=[];
        },
        cancleSplit(){
            this.showSplitInspect=false;
            this.splitItems=[];
        },
        saveSplit(){
            //console.log('save split ..........................');
            let childList=[];
            this.splitItems.forEach(item => {
                childList.push(
                    {
                        childInspectionOrder:item.inspectionCode,
                        childNum:item.splitAmount
                    }
                )
            });
            const parmas={
                id:this.currentModel.id,
                childList
            }
           // console.log('params',parmas);
          // return;
          this.loadingSaveSplit = true;

            try {
                splitInspection(parmas).then(res=>{
                if(res.code==200){
                    this.$modal.msgSuccess(this.$t('inventoryManagement.splitSuc'));
                    this.showSplitInspect=false;
                    this.loading=false;
                    this.splitItems=[];
                    this.getDetailList();
                }
                else
                {
                    this.$modal.msgError(res.msg);
                }

                }).finally(() => {
                  this.loadingSaveSplit = false;
                });
            } catch (error) {
              console.error(error);
              this.loadingSaveSplit = false;
            }


        },

        /**
         * check and show split insepction dialog
         */
        openSplitInspect(){

            if(false==this.validateSelection()){
                //need select only one row
                return;
            }
            this.showSplitInspect=true;//show split inspection dialog
            return;
        },
        /*
          end split inspection logic
         */
        groupHandleAdd() {
            if (this.ids.length === 0) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            this.editModel = {}
            let {
                factoryName,
                materialCode,
                supplierCode,
                batchAmount,
                exempted,
                isRecheck,
                experimentMaterial,
                amendBatch,
            } = this.currentModel
            console.log('maturitymaturity', this.currentModel)
            getInspectionCheck({ ids: this.ids.join(',') }).then((response) => {
                if (response.code === 200) {
                    response.msg ? this.$modal.msgWarning({message:response.msg,duration:5000}) : ''
                    getAllVersion({ ids: this.ids.join(',') ,exempted:' ',taskType:this.taskType}).then(
                        (result) => {
                            // if (result.data.params.version) {
                            this.addInspection = true
                            let versions = result.data.params?.VERSION
                                ? result.data.params.VERSION.split(',')
                                : []
                            let maturitys = result.data.params?.maturity
                                ? result.data.params.maturity.split(',')
                                : []
                            getPlanItem({
                                amendBatch: '',
                                batchAmount: result.data.batchAmount,
                                factoryCode: result.data.factoryCode,
                                materialCode,
                                supplierCode,
                                version: versions[versions.length - 1],
                            }).then((res) => {
                                this.itemList = res.data || []
                            })
                            this.versionOptions = versions
                            this.maturityOptions = maturitys
                            let batchAmount = 0
                            let inspectionLotMarks = []
                            this.selectRows.forEach((io) => {
                                batchAmount += parseFloat(io.batchAmount)
                                inspectionLotMarks.push(io.inspectionLotMark)
                            })
                            console.log('exempted===', response)
                            this.editModel = {
                                ...result.data,
                                batchAmount: result.data.batchAmount,
                                version: versions[versions.length - 1],
                                exempted: result.data.exempted || '0',
                                disabledExempted: result.data.exempted === '1',
                                isRecheck: isRecheck || '0',
                                experimentMaterial: experimentMaterial || '0',
                                maturity: maturitys[versions.length - 1],
                            }
                            this.addInspection = true
                            // } else {
                            //     this.$modal.msgWarning(
                            //         '没有查到版本号清先添加检验标准!'
                            //     )
                            // }
                        }
                    )
                }
            })
        },
        amendBatchBlur(e) {
            let { factoryCode, materialCode, supplierCode, batchAmount } =
                this.editModel
            getPlanItem({
                amendBatch: e,
                batchAmount,
                factoryCode,
                materialCode,
                supplierCode,
                version: this.editModel.version,
            }).then((res) => {
                this.itemList = res.data || []
            })
        },
        changeCurrentTactics(e){
            console.log(e,this.currentTacticslist)
            var data=this.currentTacticslist.find(item=>item.value==e)
            this.itemList=[]
            let { factoryCode, materialCode, supplierCode, batchAmount } =
                this.editModel
            getPlanItem({
                amendBatch: '',
                batchAmount,
                factoryCode,
                materialCode,
                supplierCode,
                version: this.editModel.version,
                samplingType:data.samplingType
            }).then((res) => {
                this.itemList = res.data || []
                this.editModel.samplingType=data.samplingType
                this.editModel.ttTacticsMaterielBind.currentTactics=data.value
            })
        },
        // 当前策略远程搜索方法
        remoteFatch(record) {
            carryOutList({ruleCode:record?.ruleCode}).then((res) => {
                if(Array.isArray(res.rows) ) {
                    var typelist = this.dict.type.NYIQC_RULE_TACTICS
                    // typelist.filter(item=>item.value)
                    var list = res.rows
                    this.currentTacticslist = []
                    for (let i = 0; i < typelist.length; i++) {
                        for (let index = 0; index < list.length; index++) {
                            if(list[index].currentTactics==typelist[i].value){
                                var data={
                                ...typelist[i],
                                samplingType:list[index].samplingType
                                }
                                this.currentTacticslist.push(data)
                                break
                            }
                        }
                    }
                }else {
                    this.currentTacticslist = [];
                }
            }).finally(()=>{
                
            })
        },
        changeVersion(e, index) {
            let {
                factoryCode,
                materialCode,
                supplierCode,
                amendBatch,
                batchAmount,
            } = this.currentModel
            const currentIndex = this.versionOptions.findIndex(
                (item, index) => {
                    return item == e
                }
            )
            console.log(currentIndex)
            this.editModel.maturity = this.maturityOptions[currentIndex]
            getPlanItem({
                amendBatch,
                batchAmount,
                factoryCode,
                materialCode,
                supplierCode,
                version: e,
            }).then((res) => {
                this.itemList = res.data
            })
        },
        handleDetailAdd(taskType) {
            if (this.selectRows.length === 0) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            if (this.selectRows[0].coverStatusVal === '是') {
                this.$modal.msgWarning(
                    this.$t('当前任务为冲销任务，不可发起检验！')
                )
                return
            }
            this.currentModel = this.selectRows[0]
            let lichn = this.selectRows[0].lichn
            let baseFactoryCode = this.selectRows[0].factoryCode
            let checkSupplierBatchCount = 0
            let checkFactoryNameCount = 0
            this.selectRows.forEach((io) => {
                if (lichn === io.lichn) {
                    checkSupplierBatchCount++
                }
                if (baseFactoryCode === io.factoryCode) {
                    checkFactoryNameCount++
                }
            })
            if (checkSupplierBatchCount !== this.selectRows.length) {
                this.$modal.msgWarning('请选择同一供应商批次的单号!')
                return
            }
            if (checkFactoryNameCount !== this.selectRows.length) {
                this.$modal.msgWarning('请选择同一厂区的单号!')
                return
            }
            let { factoryCode, materialCode, supplierCode } = this.selectRows[0]
            console.log('this.selectRows[0]', this.selectRows[0])
            this.loading =true
            this.taskType=taskType
            getInspectionCheck({ ids: this.ids.join(',') }).then((response) => {
                if (response.code === 200) {
                    response.msg ? this.$modal.msgWarning({message:response.msg,duration:5000}) : ''
                    getAllVersion({ ids: this.ids.join(',') ,exempted:' ',taskType:this.taskType}).then(
                        (result) => {
                            let versions = result.data.params?.VERSION
                                ? result.data.params.VERSION.split(',')
                                : []
                            let maturitys = result.data.params?.maturity
                                ? result.data.params.maturity.split(',')
                                : []
                            this.remoteFatch(result.data.ttTacticsMaterielBind)    
                            getPlanItem({
                                amendBatch: '',
                                batchAmount: this.selectRows[0].batchAmount,
                                factoryCode,
                                materialCode,
                                supplierCode,
                                version: versions[versions.length - 1],
                                samplingType:result.data.samplingType
                            }).then((res) => {
                                this.addInspection = true
                                this.itemList = res.data
                            })
                            this.versionOptions = versions
                            this.maturityOptions = maturitys
                            let batchAmount = 0
                            let inspectionLotMarks = []
                            this.selectRows.forEach((io) => {
                                batchAmount += parseFloat(io.batchAmount)
                                inspectionLotMarks.push(io.inspectionLotMark)
                            })
                            this.editModel = {
                                ...result.data,
                                batchAmount,
                                version: versions[versions.length - 1],
                                experimentMaterial: this.selectRows[0]
                                    .experimentMaterial
                                    ? this.selectRows[0].experimentMaterial
                                    : '0',
                                isRecheck: this.selectRows[0].isRecheck
                                    ? this.selectRows[0].isRecheck
                                    : '0',
                                maturity: maturitys[versions.length - 1],
                                disabledExempted:
                                    this.selectRows[0].exempted === '1',
                            }
                            this.coaBizTypeList=[]
                            this.getcoafile()
                        }
                    ).finally(()=>{
                        this.loading = false
                    })
                }else {
                    this.loading = false
                }
            }).finally(()=>{
                  this.loading = false
            })
        },
        getcoafile(){
            geFileByBiz({ bizId: this.editModel.extraId }).then((rest) => {
                rest.data.forEach((io) => {
                    if (io.bizType === 'IncomingCoaBizType') {
                        this.coaBizTypeList.unshift(io)
                    }
                })
            })
            this.$forceUpdate()
        },
        handleTop() {
            if (this.selectRows.length !== 1) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            inventoryTop({ id: this.ids[0] }).then((response) => {
                this.$modal.msgSuccess('置顶成功')
                this.getDetailList()
            })
        },
        handleApproval() {
            if (this.selectRows.length === 0) {
                this.$modal.msgWarning(
                    this.$t('inspectionManagement.pleaseSelectOne')
                )
                return
            }
            approveCheck({ ids: this.ids.join(',') }).then((response) => {
                if (response.code === 200) {
                    this.approvalOpen = true
                    if (this.selectRows[0].rejectReason) {
                        this.approvalForm.rejectReason =
                            this.selectRows[0].rejectReason
                    }
                }
            })
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.selectRows = selection
            this.ids = selection.map((item) => item.id)
            this.names = selection.map((item) => item.lichn)
            this.single = selection.length != 1
            this.multiple = !selection.length
        },
        handleSelectionDetailChange(selection) {
            this.ids = selection.map((item) => item.id)
            this.selectRows = selection
            this.detailList.forEach((io, index) => {
                console.log('includes', this.ids.includes(io.id))
                if (this.ids.includes(io.id)) {
                    io.isHighLight = true
                } else {
                    io.isHighLight = false
                }
            })
        },
        tableRowClassName({ row, rowIndex }) {
           // console.log('rowIndex', rowIndex, row)
            if (row.isHighLight === true) {
              //  console.log('rowIndex', row)
                return 'rowHighLight' //若isHighLight为true，则使用“rowHighLight”样式
            } else {
                return ''
            }
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset()
            const dictId = row.dictId || this.ids
            getType(dictId).then((response) => {
                this.form = response.data
                this.open = true
                this.title = '修改字典类型'
            })
        },
        /** 提交按钮 */
        submitForm: function () {
            this.open = false
        },
        submitApproval: function () {
            if (
                !this.approvalForm.informPeoplesName &&
                this.approvalForm.approveStatus === '1'
            ) {
                this.$modal.msgError('请选择通知人!')
                return
            }
            this.approvalOpen = false
            this.approvalForm.ids = this.ids.join(',')

            inventoryApprove(this.approvalForm).then((response) => {
                this.$modal.msgSuccess('审批成功')
                this.drawer = false
                if (
                    this.approvalForm.rejectReason !== '' &&
                    this.approvalForm.rejectReason !== null &&
                    this.approvalForm.rejectReason !== undefined
                ) {
                    this.tipsData.unshift({
                        title: this.approvalForm.rejectReason,
                    })
                    if (this.tipsData.length > 5) {
                        this.tipsData.splice(5, 1)
                    }
                    localStorage.setItem(
                        'tipsData',
                        JSON.stringify(this.tipsData)
                    )
                }

                if (this.selBtn === 1) {
                    this.getGroupList()
                } else {
                    this.getDetailList()
                }
            })
        },
        // 如果是复检单 可允许新增
        handleInspectItem() {
            this.itemList.push({
                projectName: '',
                projectCode: '',
                unitName: '',
                itemFrequency: '',
                itemFrequencyValue: '',
                decimalPlace: '',
                checkoutType: '',
                upperLimit: '',
                lowerLimit: '',
                targetValue: '',
                samplingAmount: '',
                samplingOne: '',
                samplingTwo: '',
                samplingThree: '',
                symbol: '',
                gap: '',
            })
        },
        /** 发起检验提交 */
        submitAddForm: function () {
            this.$refs['editForm'].validate((valid) => {
                if (valid) {
                    if (
                        this.editModel.exempted !== '1' &&
                        this.editModel.experimentMaterial !== '1'
                    ) {
                        this.$refs.incomingSubmit.submitAddForm()
                    } else {
                        this.submitCallback()
                    }
                } else {
                    console.log('error submit!!')
                    return false
                }
            })
        },
        submitCallback(params) {
            this.loading = true
            this.addInspection = false

            var paramss=params ? [...params] : []
            var classList=paramss

            let submitData = {
                ...this.editModel,
                classList,
            }
            checkoutIncoming(submitData)
                .then((response) => {
                    if (response.code == 200) {
                        this.$modal.msgSuccess('发起成功')
                        if (this.selBtn === 1) {
                            this.getGroupList()
                        } else {
                            this.getDetailList()
                        }
                    } else {
                        this.$modal.msgError(response.msg)
                        this.loading = false
                    }
                })
                .catch((error) => {
                    this.loading = false
                })
        },

        /** 删除按钮操作 */
        handleDelete(row, index) {
            const dictIds = row.noticeId || this.ids
            this.$modal
                .confirm(
                    '是否确认删除检验项目为"' + row.projectName + '"的数据项？'
                )
                .then(() => {
                    this.itemList.splice(index, 1)
                })
                .then(() => {})
                .catch(() => {})
        },
        /** 查看按钮操作 */
        handleView(row) {
            this.form = row
            this.open = true
            if (row.hasRead == 0) {
                readNotice(row.noticeId).then((res) => {
                    if (res.code == 200) {
                        this.handleQuery()
                    }
                })
            }
        },
        /** 编辑按钮操作 */
        handleEdit(row) {
            console.log(this.selectRows)
            this.currentModel = row
            this.drawerList = row.checkBatchList
            this.drawerTotal = row.checkBatchList.length
            this.drawer = true
        },
        /** 关闭抽屉操作 */
        handleClose(row) {
            this.drawer = false
        },
        /** 导出按钮操作 */
        handleExport() {
            let params = { ...this.queryParams }
            let dateRange={};
            dateRange["beginTime"]=this.queryParams.params[0];
            dateRange["endTime"]=this.queryParams.params[1];
            params.params=dateRange;

            this.download(
                'ny-iqc/inventory/export',
                {
                    ...params
                },
                `type_${new Date().getTime()}.xlsx`
            )
        },
        /** 刷新缓存按钮操作 */
        handleRefreshCache() {
            refreshCache().then(() => {
                this.$modal.msgSuccess('刷新成功')
            })
        },
        /** 删除按钮操作 */
        handleDeleteItem(row, index) {
            const dictIds = row.noticeId || this.ids
            this.$modal
                .confirm(
                    '是否确认删除检验项目为"' + row.projectName + '"的数据项？'
                )
                .then(() => {
                    this.itemList.splice(index, 1)
                })
                .then(() => {})
                .catch(() => {})
        },
    },
}
</script>
<style lang="scss" scoped>
::v-deep .el-card {
    padding-top: 20px;
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 4px;
    padding-bottom: 20px;
}
::v-deep .el-aside {
    padding: 0;
    margin-bottom: 0;
}
.content-style {
    border: 0px;
    box-shadow: 0px 2px 6px 0px rgba(0, 0, 0, 0.08);
    border-radius: 2px;
    background-color: white;
    margin-top: 10px;
}
::v-deep .el-button-group .selBtn {
    background: #fff;
    border: 1px solid #0b7be3;
    color: #0b7be3;
}
::v-deep .el-button-group .unselBtn {
    background: #fff;
    border: 1px solid #ededf2;
    color: #666666;
}
::v-deep .el-table .el-table__header-wrapper .el-table__cell, ::v-deep .el-table .el-table__fixed .el-table__fixed-header-wrapper .el-table__cell {
    height: 70px;
}
::v-deep .el-table__header-wrapper {
  height: 70px;
}
.header-left {
    float: left;
    font-size: 14px;
    font-family: PingFangSC-Semibold, PingFang SC;
    font-weight: 600;
    color: #333333;
    line-height: 40px;
    display: flex;
    justify-content: center;
    border-bottom: 2px solid #0b7be3;
}
.header-right {
    float: right;
}
.container-header {
    float: left;
    width: 100%;
    border-bottom: 1px solid #ededf2;
}
.container-table {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.mb8 {
    float: left;
    margin-top: 6px;
    width: 100%;
}
.drawer-footer {
    display: flex;
    position: relative;
    z-index: 9999;
    bottom: -40px;
    height: 40px;
    justify-content: center;
    width: 100%;
}
.drawer-close {
    background: #f7f8fa;
    border-color: #f7f8fa;
}
::v-deep .el-form-item {
    margin-bottom: 3px !important;
}
::v-deep .rowHighLight {
    background: oldlace;
}
</style>
